package com.oocl.euc.core.builder;

import com.oocl.euc.core.maintenance.model.ApplicationKey;
import com.oocl.euc.core.maintenance.model.ApplicationKeyValue;
import com.oocl.euc.core.maintenance.repository.ApplicationKeyRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ApplicationKeyBuilder {

    private ApplicationKey applicationKey;

    @Autowired
    private ApplicationKeyRepository applicationKeyRepository;

    public ApplicationKeyBuilder defaultBuilder() {
        this.applicationKey = new ApplicationKey();
        this.applicationKey.setAppKey("TEST APP KEY");
        this.applicationKey.setDescription("TEST DESC");
        return this;
    }

    public ApplicationKeyBuilder withAppKey(String appKey) {
        applicationKey.setAppKey(appKey);
        return this;
    }

    public ApplicationKeyBuilder withDescription(String description) {
        applicationKey.setDescription(description);
        return this;
    }

    public ApplicationKeyBuilder withApplicationKeyValueList(List<ApplicationKeyValue> applicationKeyValueList) {
        applicationKey.setApplicationKeyValueList(applicationKeyValueList);
        return this;
    }

    public ApplicationKeyBuilder withDefaultValue(String defaultValue) {
        applicationKey.setDefaultValue(defaultValue);
        return this;
    }

    public ApplicationKey create() {
        return applicationKey;
    }

    public ApplicationKey saveToDB() {
        applicationKeyRepository.save(applicationKey);
        return applicationKey;
    }
}
